Alter PROCEDURE [dbo].[SPTopicsGetUnanswered]
(
	@StartIndex int = 0
	,@Length int = 10
)
AS

SELECT *
FROM
	(SELECT
		ROW_NUMBER() OVER (ORDER BY T.TopicId) AS RowNumber
		,T.TopicId
		,T.TopicTitle
		,T.TopicShortName
		,T.TopicDescription
		,T.TopicCreationDate
		,T.TopicViews
		,T.TopicReplies
		,T.UserId
		,T.TopicTags
		,T.TopicIsClose
		,T.TopicOrder
		,T.LastMessageId
		,U.UserName
		,T.ForumId
		,F.ForumName
		,F.ForumShortName
	FROM
	Topics T    
		INNER JOIN Users U ON U.UserId = T.UserId    
		INNER JOIN Forums F ON F.ForumId = T.ForumId    
	WHERE    
		T.Active = 1    
		AND    
		F.Active = 1  
		AND
		T.TopicReplies = 0 -- Unanswered
		AND
		T.TopicOrder IS NULL -- Not sticky	
	) T
WHERE
	RowNumber BETWEEN @StartIndex+1 AND @StartIndex + @Length
	
	
GO


IF EXISTS(SELECT * FROM [dbo].[sysobjects]
	WHERE ID = object_id(N'[dbo].[SPTopicsGetUnansweredCount]') 
	AND xtype in ('P'))
	DROP PROCEDURE SPTopicsGetUnansweredCount;
GO

Create procedure SPTopicsGetUnansweredCount
As
Begin

	Select Count(*) as [Count]
	FROM
		TopicsComplete T with (nolock)
	WHERE
		T.TopicReplies = 0 -- Unanswered
		AND
		T.TopicOrder IS NULL -- Not sticky	
End
go


